var slf = {};
/**
 * ios回退加载
 * @param event
 */
window.onpageshow = function(event) {
	if (event.persisted) {
	window.location.reload();
	}
	};

slf.perSex=0;
slf.schoolId="a";
slf.slfToken="slfToken";
//Cookie名称
/**
 * 设置Cookie 有效时间30天
 */
slf.setCookie = function(k,v){
	$.cookie(k,v,{expiress:31});
}
/**
 * 过去Cookie值
 */
slf.getCookie = function(k){
	return $.cookie(k);
}

/**
 * 用户对象
 */
slf.user = {};

slf.defau = {};

slf.childList={};
//默认课程图片
slf.defau.courseIcon = function(v){
	var courseIcon = ["https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/course-oblong-01.png",
	                  "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/course-oblong-02.png",
	                  "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/course-oblong-03.png",
	                  "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/course-oblong-04.png",
	                  "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/course-oblong-03.png"
	                  ];
	return courseIcon[v % 5];
}
//需要添加个默认头像
slf.defau.userIcon = function(v){
	var userIcon = ["https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/head-circle-01.png",
	                "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/head-circle-02.png",
	                "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/head-circle-03.png",
	                "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/head-circle-05.png",
	                "https://userweb-client-png.oss-cn-beijing.aliyuncs.com/slf-formal/head-circle-02.png"];
	return userIcon[v % 5];
}
/**
 * 判断是否为空
 */
slf.isBlank = function(value) {
	if (value == undefined) {
		return true;
	}
	if (value == null) {
		return true;
	}
	if (value == "") {
		return true;
	}
	return false;
}

/**
 * ajax 请求
 */
slf.ajax = function() {
	$("#my-modal-loading").modal('open');
	var operate = arguments[0] || {};
	var url =operate.url || "";
	var async = typeof (operate.async) == 'boolean' ? operate.async : true;
	var param = operate.param || {};
	var dataType = operate.dataType || "json";
	var type = operate.type || "POST";
	var contentType = operate.contentType || "application/x-www-form-urlencoded; charset=utf-8";
	var loading = operate.loading || '正在处理中...';
	var success = operate.success || function(data) {};
	var beforeSend = operate.beforeSend || function(data) {};
	var complete = operate.complete || function(data) {};
	var error = operate.error || function(data) {};
	param.token = slf.getCookie(slf.slfToken);
	if (!slf.isBlank(url)) {
		url="/web"+url
		$.ajax({
			type : type,
			url : url,
			contentType : contentType,
			dataType : dataType,
			data : param,
			async : async,
			beforeSend : function(data){
				beforeSend(data);
			},
			error : function(data){
				error(data);
			},
			complete : function(data) {
				complete(data);
			},
			success : function(data) {
				var url = window.location.href;
				var index = url .lastIndexOf("\/");  
				url  = url .substring(index + 1, url .length);
				if(url=="index.html"||url=="course_pack.html"){
					setTimeout(function(){
					  $('#my-modal-loading').modal('close');
					},3000);
				}else{
					$("#my-modal-loading").modal('close');
				}
				if(data){
					if(data.res == "234"){
						alert(data.resMsg);
						window.location.href = "/slf/login.html"
					}else{
						success(data);
					}
				}
			}
		});
	}
}

/**
 * 获取用户信息
 */
slf.getUser = function(){
	slf.ajax({
		url : "/user/getUer",
		async : false,
		success : function(data){
			slf.user = data.obj;
		}
	});
}
/**
 * 获取所有孩子信息
 */
slf.getChildList = function (){
    slf.ajax({
        url:'/myCenter/getUserChildrenCourse',
        type:'post',
        async : false,
        param:JSON.stringify({type: "0"}),
        contentType : 'application/json;charset=utf-8',
        success:function(data){
        	console.log(data)
           if(data.res==1){
           	slf.childList=data.obj;
		   }
        }
    });
}

slf.getSequenceChild=function (){
    slf.getChildList();
    for(var a=0,b=slf.childList.length;a<b;a++){
        if(slf.childList[a].sequence==0){
        	slf.perSex=slf.childList[a].sex;
        	slf.schoolId=slf.childList[a].schoolId;
        	return slf.childList[a]
            //return slf.childList[a].childrenId;
        }
    }
}
//是否登录判断
slf.checkSign=function (){
    var loginSign=$.cookie('slfCookie');
    if(loginSign!=undefined){
    	return true
    }else{
    	return false
    }
}
/**
 * 获取url参数
 */
slf.getQueryStringByName = function(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return decodeURI(result[1]);
}

slf.weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; //星期几
slf.orderState = {"1":"已预约成功","2":"预约失败","3":"预约结束，即将开课"};
slf.AttendanceType = {"1":"正常", "2":"迟到","3":"早退"};